'''
Created on 2012/02/14

@author: mercury
'''
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

import pyglet
from pyglet.gl import *

from cocos.director import *
from cocos.menu import *
from cocos.scene import *
from cocos.layer import *
from script import *
from cocos.sprite import *
from cocos.text import *

class MainScene(Layer):
    '''
    MainScene
    '''


    def __init__(self):
        '''
        Constructor
        '''
        super(MainScene,self).__init__()
        x , y = director.get_window_size()
        #add background image in center
        background = Sprite("background.png",(x/2,y/2))
        self.add(background,z=-1,name="background")
    
    @staticmethod
    def init():
        return Scene(MainScene(),MultiplexLayer(MainMenu(), OptionMenu()))
        
class MainMenu(Menu):
    """
    Main Menu
    """
    
    def __init__(self):
        super(MainMenu,self).__init__('MagicCaps')
        #add font directory to paths
        pyglet.font.add_directory('.')

        # you can override the font that will be used for the title and the items
        #load font name
        self.font_title['font_name'] = 'You Are Loved'
        self.font_title['font_size'] = 72

        self.font_item['font_name'] = 'You Are Loved'
        self.font_item_selected['font_name'] = 'You Are Loved'
        #menu`s align
        self.menu_valign = CENTER
        self.menu_halign = CENTER
        
        items = []
        #add item to Menu and bind method
        items.append( MenuItem('New Game', self.on_new_game ) )
        items.append( MenuItem('Options', self.on_options ) )
        items.append( MenuItem('staff', self.on_staff ) )
        items.append( MenuItem('Quit', self.on_quit ) )
        
        self.create_menu( items, zoom_in(), zoom_out(), shake())
        
    def on_new_game(self):
        #change to game scene
        game = GameScene()
        director.run(Scene(game))
        
    def on_options(self):
        self.parent.switch_to(1)
    
    def on_staff(self):
        #change to staff scene
        staff = StaffScene()
        director.run(Scene(staff))
    
    def on_quit(self):
        director.pop()
        
    
class OptionMenu(Menu):
    """
    options menu
    """
    def __init__(self):
        
        super(OptionMenu ,self ).__init__('Game Option')
        self.font_title['font_name'] = 'You Are Loved'
        self.font_title['font_size'] = 72

        self.font_item['font_name'] = 'You Are Loved'
        self.font_item_selected['font_name'] = 'You Are Loved'

        self.menu_valign = BOTTOM
        self.menu_halign = RIGHT

        items = []
        #TODO:add options to optionMenu
            
if __name__ == "__main__" :
    director.init(resizable=False, width=800, height=600)
    director.run( MainScene.init() )